package Client.PokerClient.src;

import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.SwingUtilities;
/**
 * Klasa Mouse Listener dla klasy GameWindow.
 * @author Artur Smolibowski
 */
public class GameMouseListener implements MouseListener {
  /**
   * Referencja do klasy glownej.
   */
  private Client client;
  /**
   * Konstruktor klasy.
   * @param client Referencja do klasy glownej.
   */
  GameMouseListener(Client client) {
    this.client=client;
  }
  /**
   * Metoda zajmujaca sie zdarzeniami myszki wystepujacymi w klasie GameWindow.
   */
  public void mouseClicked(MouseEvent e) {
	PointerInfo a = MouseInfo.getPointerInfo();
    Point point = new Point(a.getLocation());
    SwingUtilities.convertPointFromScreen(point, e.getComponent());
    int x=((int) point.getX());
    int y=((int) point.getY())-25;
    int ReplaceCards[] = client.getGameController().getReplaceCards();
    int numberOfReplaceCards=0;
    for(int i=0;i<ReplaceCards.length;i++)
      if(ReplaceCards[i]>0) numberOfReplaceCards++;
	    
    if(y>450 && y<570 && client.getGameController().isHostPlay())
      if(x>175 && x<625)
        if(x<255) { if(ReplaceCards[0]==0 && numberOfReplaceCards<4) ReplaceCards[0]=20; else ReplaceCards[0]=0; }
        else if(x<265) ;
        else if(x<345) { if(ReplaceCards[1]==0 && numberOfReplaceCards<4) ReplaceCards[1]=20; else ReplaceCards[1]=0; }
        else if(x<355) ;
        else if(x<435) { if(ReplaceCards[2]==0 && numberOfReplaceCards<4) ReplaceCards[2]=20; else ReplaceCards[2]=0; }
        else if(x<445) ;
        else if(x<525) { if(ReplaceCards[3]==0 && numberOfReplaceCards<4) ReplaceCards[3]=20; else ReplaceCards[3]=0; }
        else if(x<535) ;
        else { if(ReplaceCards[4]==0 && numberOfReplaceCards<4) ReplaceCards[4]=20; else ReplaceCards[4]=0; }
    
    client.getGameController().setReplaceCards(ReplaceCards);
    client.getGameController().Refresh();
  }
  /**
   * Komunikat nieobslugiwany.
   */
  public void mouseEntered(MouseEvent arg0) {

  }
  /**
   * Komunikat nieobslugiwany.
   */
  public void mouseExited(MouseEvent arg0) {

  }
  /**
   * Komunikat nieobslugiwany.
   */
  public void mousePressed(MouseEvent arg0) {

  }
  /**
   * Komunikat nieobslugiwany.
   */
  public void mouseReleased(MouseEvent arg0) {

  }
}
